﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using Awesomium.Core;
using System.Windows.Forms;

namespace BrowserPL3
{
    /// <summary>
    /// Interaction logic for MainStructure.xaml
    /// </summary>
    public partial class MainStructure : Window
    {
        public MainStructure()
        {
            InitializeComponent();
        }
        private void back_click(object sender, RoutedEventArgs e)
        {
            try
            {
                //check if can go back
                if (WebBrowser1.CanGoBack())
                {
                    WebBrowser1.GoBack();
                }
            }
            catch{}
            
        }


        private void next_click(object sender, RoutedEventArgs e)
        {
            try
            {
                //check if can go forward
                if (WebBrowser1.CanGoForward())
                {
                    WebBrowser1.GoForward();
                }
            }
            catch { }
        }

        private void refresh_click(object sender, RoutedEventArgs e)
        {
            WebBrowser1.Reload(true);
        }

        private void Text_Key_Down(object sender, System.Windows.Input.KeyEventArgs e)
        {
            if (e.Key == Key.Enter)
            {
                try
                {
                    if ((URL_Text.Text.Contains(".com") || (URL_Text.Text.Contains(".net"))))
                    {

                        WebBrowser1.Source = URL_Text.Text.ToUri();

                       

                    }

                    else
                    {

                        WebBrowser1.Source = new Uri("https://www.google.com.eg/#q=" + URL_Text.Text);


                    }
                }
                catch { }
              
            }
        }

        private void URL_Text_TextChanged(object sender, TextChangedEventArgs e)
        {

        }

        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            WebBrowser1.Source = new Uri(Properties.Settings.Default.Homepage);
        }

        private void MenuItem_Click_1(object sender, RoutedEventArgs e)
        {

        }

       

        private void Exit(object sender, RoutedEventArgs e)
        {
            App.Current.Shutdown();
        }

        private void setting_Click(object sender, RoutedEventArgs e)
        {
            SettingWindow set = new SettingWindow();
            set.Show();
        }

       

        private void WebBrowser1_LoadingFrameComplete(object sender, FrameEventArgs e)
        {
            loadImg.Visibility = Visibility.Hidden;

        }

        private void WebBrowser1_LoadingFrame(object sender, LoadingFrameEventArgs e)
        {
            loadImg.Visibility = Visibility.Visible;
        }

        private void WebBrowser1_AddressChanged(object sender, UrlEventArgs e)
        {

            var uri = WebBrowser1.Source.AbsoluteUri.ToUri();
            URL_Text.Text = uri.ToString();
        }

        

    }
}
